#include "DfaTest.h"

DfaTest::DfaTest()
{
}

DfaTest::~DfaTest()
{
}

void testString(Dfa<string> &dfa, string &word)
{
	if(dfa.acceptString(word) == false)
	{
		cout << "De string: " << word << " wordt niet geaccepteerd door de Dfa automaat!" << endl;
	} else { cout << "De string: " << word <<  " is geaccepteerd door de Dfa Automaat " << endl;}
}

void DfaTest::testProgram()
{
	cout<<"Dfa Test"<<endl << "==================================="<<endl<<endl;
		
	//============================================================
	set<Transition<string> > transitions;
	set<string> endStates;
	transitions.clear();
	transitions.insert(Transition<string>("q0", 'b', "q0"));
	transitions.insert(Transition<string>("q0", 'a', "q1"));
	transitions.insert(Transition<string>("q1", 'b', "q1"));
	transitions.insert(Transition<string>("q1", 'a', "q0"));
	transitions.insert(Transition<string>("q1", 'b', "q1"));
		
	endStates.clear();
	endStates.insert("q0");
	Dfa<string> &dfa1 = *new Dfa<string>("q0", transitions, endStates);
	cout << "dfa1" << endl << dfa1 << "Genereerd het/de volgende woord(en): " << dfa1.getLanguage(6)<<endl<<endl;
	
	string testDfa1 = "aa";
	testString(dfa1, testDfa1);
	cout << endl<<endl; 
	//============================================================

	transitions.clear();
	endStates.clear();
	transitions.insert(Transition<string>("q0", 'b', "q0"));
	transitions.insert(Transition<string>("q0", 'a', "q1"));
	transitions.insert(Transition<string>("q1", 'a', "q0"));
	transitions.insert(Transition<string>("q1", 'b', "q1"));
	endStates.insert("q0");
	Dfa<string> &dfa2 = *new Dfa<string>("q0", transitions, endStates);
	cout << "dfa2" << endl << dfa1 << "Genereerd het/de volgende woord(en): " << dfa2.getLanguage(3)<<endl<<endl;
	
	string testDfa2 = "aaa";
	testString(dfa2, testDfa2);
	cout << endl<<endl; 

	//============================================================
	//voorbeeld 2.8 uit dictaat
	transitions.clear();
	endStates.clear();
	transitions.insert(Transition<string>("q0", 'a', "q1"));
	transitions.insert(Transition<string>("q0", 'b', "q4"));
	transitions.insert(Transition<string>("q1", 'b', "q2"));
	transitions.insert(Transition<string>("q2", 'b', "q4"));
	transitions.insert(Transition<string>("q2", 'a', "q3"));
	transitions.insert(Transition<string>("q3", 'b', "q2"));
	transitions.insert(Transition<string>("q3", 'a', "q1"));
	transitions.insert(Transition<string>("q4", 'a', "q4"));
	transitions.insert(Transition<string>("q4", 'b', "q4"));

	endStates.insert("q0");
	endStates.insert("q2");
	endStates.insert("q3");
	Dfa<string> &dfa3 = *new Dfa<string>("q0", transitions, endStates);
	cout << "dfa3" << endl << dfa3 << "Genereerd het/de volgende woord(en): " << dfa3.getLanguage(6)<<endl<<endl;
	
	string testDfa31 = "a";
	string testDfa32 = "aa";
	string testDfa33 = "baba";
	string testDfa34 = "ababb";
	string testDfa35 = "abaabaa";
	testString(dfa3, testDfa31);
	testString(dfa3, testDfa32);
	testString(dfa3, testDfa33);
	testString(dfa3, testDfa34);
	testString(dfa3, testDfa35);
	cout << endl<<endl; 

	//============================================================
}
